package br.ufrpe.bsi.pvs.view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.GraphicsEnvironment;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

import br.ufrpe.bsi.pvs.model.roupa.Roupa;
import br.ufrpe.bsi.pvs.view.admin.TelaLogin;
import br.ufrpe.bsi.pvs.view.admin.TelaMenuPrincipal;
import br.ufrpe.bsi.pvs.view.assistant.TelaAssistente;
import br.ufrpe.bsi.pvs.view.assistant.TelaDetalhamento;
import br.ufrpe.bsi.pvs.view.assistant.TelaResultados;

public class PvsFrame extends javax.swing.JFrame {

	public static final PvsFrame INSTANCE = new PvsFrame();

	private PvsFrame() {
		super("Personal Virtual Stylist");
		// loadFonts();
		getContentPane().setBackground(Color.WHITE);
		setBackground(Color.WHITE);
		setMinimumSize(new Dimension(1200, 600));
		setResizable(false);
		setLocationRelativeTo(null);
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		setAppIcon();
	}

	public void createAndShowGUI() {
		show(TelaHome.INSTANCE);
		setVisible(true);
	}

	public void show(JPanel toShow) {
		setContentPane(toShow);
		revalidate();
	}

	public void home() {
		show(TelaAssistente.INSTANCE);
	}

	public void login() {
		show(TelaLogin.INSTANCE);
	}

	public void menu() {
		show(TelaMenuPrincipal.INSTANCE);
	}
	
	public void result(List<Roupa> result) {
		show(TelaResultados.INSTANCE);
		TelaResultados.INSTANCE.carregarTabela(result);
	}

	private void setAppIcon() {
		setIconImage(new ImageIcon(getClass().getResource("/images/icon.png"))
				.getImage());
	}

	private void loadFonts() {
		try {
			URL url = getClass().getResource("/font/Gabriola.ttf");
			GraphicsEnvironment ge = GraphicsEnvironment
					.getLocalGraphicsEnvironment();
			ge.registerFont(Font.createFont(Font.TRUETYPE_FONT,
					new File(url.toURI())));
		} catch (IOException | FontFormatException | URISyntaxException e) {
			e.printStackTrace();
		}
	}
}
